home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-cm-m.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  7KB  |  244 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-cx-mat.h"
  34. #include "ov-re-mat.h"
  35. #include "ov-typeinfo.h"
  36. #include "op-cm-m.h"
  37. #include "ops.h"
  38. #include "xdiv.h"
  39. #include "xpow.h"
  40.  
  41. // complex matrix by matrix ops.
  42.  
  43. static octave_value
  44. add (const octave_value& a1, const octave_value& a2)
  45. {
  46.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  47.  
  48.   return octave_value (v1.complex_matrix_value () + v2.matrix_value ());
  49. }
  50.  
  51. static octave_value
  52. sub (const octave_value& a1, const octave_value& a2)
  53. {
  54.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  55.  
  56.   return octave_value (v1.complex_matrix_value () - v2.matrix_value ());
  57. }
  58.  
  59. static octave_value
  60. mul (const octave_value& a1, const octave_value& a2)
  61. {
  62.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  63.  
  64.   return octave_value (v1.complex_matrix_value () * v2.matrix_value ());
  65. }
  66.  
  67. static octave_value
  68. div (const octave_value& a1, const octave_value& a2)
  69. {
  70.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  71.  
  72.   return xdiv (v1.complex_matrix_value (), v2.matrix_value ());
  73. }
  74.  
  75. static octave_value
  76. pow (const octave_value&, const octave_value&)
  77. {
  78.   error ("can't do A ^ B for A and B both matrices");
  79.   return octave_value ();
  80. }
  81.  
  82. static octave_value
  83. ldiv (const octave_value& a1, const octave_value& a2)
  84. {
  85.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  86.  
  87.   return xleftdiv (v1.complex_matrix_value (), v2.matrix_value ());
  88. }
  89.  
  90. #define BOOL_OP(OP, ONE_EMPTY_RESULT, TWO_EMPTY_RESULT) \
  91.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), \
  92.          Matrix, m2, v2.matrix_value (), \
  93.          real (m1 (i, j)) OP m2 (i, j), #OP, \
  94.          ONE_EMPTY_RESULT, TWO_EMPTY_RESULT)
  95.  
  96. static octave_value
  97. lt (const octave_value& a1, const octave_value& a2)
  98. {
  99.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  100.  
  101.   BOOL_OP (<, Matrix (), Matrix ());
  102. }
  103.  
  104. static octave_value
  105. le (const octave_value& a1, const octave_value& a2)
  106. {
  107.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  108.  
  109.   BOOL_OP (<=, Matrix (), Matrix ());
  110. }
  111.  
  112. static octave_value
  113. eq (const octave_value& a1, const octave_value& a2)
  114. {
  115.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  116.  
  117.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  118.          Matrix, m2, v2.matrix_value (),
  119.          m1 (i, j) == m2 (i, j), "==",
  120.          0.0, 1.0);
  121. }
  122.  
  123. static octave_value
  124. ge (const octave_value& a1, const octave_value& a2)
  125. {
  126.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  127.  
  128.   BOOL_OP (>=, Matrix (), Matrix ());
  129. }
  130.  
  131. static octave_value
  132. gt (const octave_value& a1, const octave_value& a2)
  133. {
  134.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  135.  
  136.   BOOL_OP (>, Matrix (), Matrix ());
  137. }
  138.  
  139. static octave_value
  140. ne (const octave_value& a1, const octave_value& a2)
  141. {
  142.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  143.  
  144.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  145.          Matrix, m2, v2.matrix_value (),
  146.          m1 (i, j) != m2 (i, j), "!=",
  147.          1.0, 0.0);
  148. }
  149.  
  150. static octave_value
  151. el_mul (const octave_value& a1, const octave_value& a2)
  152. {
  153.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  154.  
  155.   return product (v1.complex_matrix_value (), v2.matrix_value ());
  156. }
  157.  
  158. static octave_value
  159. el_div (const octave_value& a1, const octave_value& a2)
  160. {
  161.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  162.  
  163.   return quotient (v1.complex_matrix_value (), v2.matrix_value ());
  164. }
  165.  
  166. static octave_value
  167. el_pow (const octave_value& a1, const octave_value& a2)
  168. {
  169.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  170.  
  171.   return elem_xpow (v1.complex_matrix_value (), v2.matrix_value ());
  172. }
  173.  
  174. static octave_value
  175. el_ldiv (const octave_value& a1, const octave_value& a2)
  176. {
  177.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  178.  
  179.   return quotient (v2.matrix_value (), v1.complex_matrix_value ());
  180. }
  181.  
  182. static octave_value
  183. el_and (const octave_value& a1, const octave_value& a2)
  184. {
  185.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  186.  
  187.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  188.          Matrix, m2, v2.matrix_value (),
  189.          m1 (i, j) != 0.0 && m2 (i, j), "&",
  190.          Matrix (), Matrix ());
  191. }
  192.  
  193. static octave_value
  194. el_or (const octave_value& a1, const octave_value& a2)
  195. {
  196.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_matrix&);
  197.  
  198.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  199.          Matrix, m2, v2.matrix_value (),
  200.          m1 (i, j) != 0.0 || m2 (i, j), "|",
  201.          Matrix (), Matrix ());
  202. }
  203.  
  204. static octave_value
  205. assign (octave_value& a1, const octave_value_list& idx,
  206.     const octave_value& a2)
  207. {
  208.   CAST_BINOP_ARGS (octave_complex_matrix&, const octave_matrix&);
  209.  
  210.   v1.assign (idx, v2.complex_matrix_value ());
  211.   return octave_value ();
  212. }
  213.  
  214. void
  215. install_cm_m_ops (void)
  216. {
  217.   INSTALL_BINOP (add, octave_complex_matrix, octave_matrix, add);
  218.   INSTALL_BINOP (sub, octave_complex_matrix, octave_matrix, sub);
  219.   INSTALL_BINOP (mul, octave_complex_matrix, octave_matrix, mul);
  220.   INSTALL_BINOP (div, octave_complex_matrix, octave_matrix, div);
  221.   INSTALL_BINOP (pow, octave_complex_matrix, octave_matrix, pow);
  222.   INSTALL_BINOP (ldiv, octave_complex_matrix, octave_matrix, ldiv);
  223.   INSTALL_BINOP (lt, octave_complex_matrix, octave_matrix, lt);
  224.   INSTALL_BINOP (le, octave_complex_matrix, octave_matrix, le);
  225.   INSTALL_BINOP (eq, octave_complex_matrix, octave_matrix, eq);
  226.   INSTALL_BINOP (ge, octave_complex_matrix, octave_matrix, ge);
  227.   INSTALL_BINOP (gt, octave_complex_matrix, octave_matrix, gt);
  228.   INSTALL_BINOP (ne, octave_complex_matrix, octave_matrix, ne);
  229.   INSTALL_BINOP (el_mul, octave_complex_matrix, octave_matrix, el_mul);
  230.   INSTALL_BINOP (el_div, octave_complex_matrix, octave_matrix, el_div);
  231.   INSTALL_BINOP (el_pow, octave_complex_matrix, octave_matrix, el_pow);
  232.   INSTALL_BINOP (el_ldiv, octave_complex_matrix, octave_matrix, el_ldiv);
  233.   INSTALL_BINOP (el_and, octave_complex_matrix, octave_matrix, el_and);
  234.   INSTALL_BINOP (el_or, octave_complex_matrix, octave_matrix, el_or);
  235.  
  236.   INSTALL_ASSIGNOP (octave_complex_matrix, octave_matrix, assign);
  237. }
  238.  
  239. /*
  240. ;;; Local Variables: ***
  241. ;;; mode: C++ ***
  242. ;;; End: ***
  243. */
  244.